import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { ApiService } from 'src/app/core/api';

@Injectable()
export class AgencyDetailActivate implements Resolve<any> {
	constructor(private apiService: ApiService) {}
	resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
		let url = route.queryParams['travelAgencyId'] ? '通过旅行社编号调用旅游社详情' : '旅游社详情';
		console.log(url,'======',route.queryParams)
		return this.apiService.get(url, route.queryParams).then((e: any) => {
			const data: any = {};
			data.del = e;
			data.rate = [{ url: '../../../assets/icons/off.png' }, { url: '../../../assets/icons/off.png' }, { url: '../../../assets/icons/off.png' }, { url: '../../../assets/icons/off.png' }, { url: '../../../assets/icons/off.png' }];
			data.imgs = e.travelAgencyForUserView.images.split(',');
			for (let i = 0; i < e.travelAgencyForUserView.starLevel; i++) {
				data.rate[i] = { url: '../../../assets/icons/on.png' };
			}
			for (let item = 0; item < e.agencyTravelGuideList.length; item++) {
			  e.agencyTravelGuideList[item]['isConcern'] = false;
			}
			data.serviceStatus = e.travelAgencyForUserView.serviceStatus;
			data.serviceTime = e.travelAgencyForUserView.serviceTime;
			console.log(data);
			return data;
		  }).catch(res => {
			return res;
		});
	}
}
